package com.cloudkinto.service.orderback.impl;

import com.aliyun.oss.model.OSSObjectSummary;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudkinto.common.DicBusinessConstant;
import com.cloudkinto.common.DicBusinessItemConstant;
import com.cloudkinto.common.common.DateUtils;
import com.cloudkinto.common.constant.GlobalConstants;
import com.cloudkinto.common.constant.SysConstant;
import com.cloudkinto.common.exception.BizException;
import com.cloudkinto.common.utils.OrderCodeUtil;
import com.cloudkinto.common.utils.StringsUtil;
import com.cloudkinto.common.utils.TimeUtils;
import com.cloudkinto.common.utils.ali.AliOss;
import com.cloudkinto.common.utils.dict.StaticDict;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.dao.*;
import com.cloudkinto.entity.*;
import com.cloudkinto.service.company.CompanyService;
import com.cloudkinto.service.dic.DicBusinessItemService;
import com.cloudkinto.service.dic.vo.DicItemRes;
import com.cloudkinto.service.file.FileService;
import com.cloudkinto.service.finance.CostRecordService;
import com.cloudkinto.service.operate.OperateRecordService;
import com.cloudkinto.service.orderback.OrderBackService;
import com.cloudkinto.service.orderback.vo.*;
import com.cloudkinto.service.product.ProductStockFlowingService;
import com.cloudkinto.service.shipprice.ShipPriceService;
import com.cloudkinto.service.shop.ShopService;
import com.cloudkinto.service.stock.StockLogService;
import com.cloudkinto.service.storage.StorageService;
import com.cloudkinto.service.user.WxUserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.util.*;

/**
 * <p>
 * service实现类
 * </p>
 *
 * @author zhangyy
 * @since 2020-08-05
 */
@Service
@Transactional(rollbackFor = Exception.class)//事务回滚
public class OrderBackServiceImpl extends ServiceImpl<OrderBackDao, OrderBackDo> implements OrderBackService {
    @Autowired
    private OrderBackDao dao;
    @Autowired
    private OrderBackProductDao orderBackProductDao;
    @Autowired
    private ProductInfoDao productInfoDao;
    @Autowired
    private FileService fileService;
    @Autowired
    private StockRecordDao stockRecordDao;
    @Autowired
    private CompanyService companyService;

    @Autowired
    private StorageService storageService;
    @Autowired
    private ShopService shopService;
    @Autowired
    private DicBusinessItemDao dicBusinessItemDao;
    @Autowired
    private DicBusinessItemService dicBusinessItemService;
    @Autowired
    private CostRecordService costService;
    @Autowired
    private StockLogService stockLogService;
    @Autowired
    private WxUserService wxUserService;
    @Autowired
    private ThreadPoolTaskExecutor executor;
    @Autowired
    private OrderOutputDao orderOutputDao;
    @Autowired
    private ShipPriceService mShipPriceService;
    @Autowired
    private ProductStockRackDao productStockRackDao;
    @Autowired
    private ProductStockDao productStockDao;
    @Autowired
    private ProductStockFlowingService productStockFlowingService;
    @Autowired
    private OperateRecordService operateRecordDao;


    @Value("${gbc.uploadPath.filePath}")
    private String filePath;
    @Value("${gbc.uploadPath.filePathTemp}")
    private String filePathTemp;

    @Override
    public SingleResult addInit(Long userId, Long companyId) {
        Map<String, List> resultMap = new HashMap<>();
        resultMap.put("storageList", storageService.getStorageList());
        resultMap.put("shopList", shopService.selectShopListInit(userId, companyId));
        resultMap.put("companyTree", companyService.tree());
        return SingleResult.success(resultMap);
    }

    @Override
    public SingleResult updateStatusInit() {
        List<DicItemRes> dicItemList = dicBusinessItemService.getDicItemList(DicBusinessConstant.orderBackStatus);
        return SingleResult.success(dicItemList);
    }

    @Override
    public void updateStatus(OrderBackUpdateStatusReq req, Long userId) {
        OrderBackDo orderBackDo = dao.selectById(req.getId());
        orderBackDo.setStatus(req.getStatus());
        orderBackDo.setUpdateBy(userId);
        orderBackDo.setUpdateTime(new Date());
        //如果是已到货状态 编辑到货时间
        if (req.getStatus().equals(DicBusinessItemConstant.orderBackInStatus)) {
            orderBackDo.setArrivalTime(new Date());
        }
        dao.updateById(orderBackDo);


    }

    @Override
    public OrderBackAddReq add(OrderBackAddReq req, Long userId, Long companyId) {
        OrderBackDo entityDo = new OrderBackDo();
        BeanUtils.copyProperties(req, entityDo);
        handlerAddBefore(entityDo, userId);
        entityDo.setCompanyId(companyId);
        if (StringUtils.isNotBlank(req.getTrackNumber())) {//如果有追踪号 自动审核为已审核状态
            entityDo.setStatus(DicBusinessItemConstant.orderBackCheckStatus);
        } else {
            entityDo.setStatus(DicBusinessItemConstant.orderBackCreateStatus);
        }
        dao.insert(entityDo);
        if (StringUtils.isBlank(entityDo.getOrderOutNumber())) {
            entityDo.setOrderOutNumber(OrderCodeUtil.getBackOrderNumber(entityDo.getId()));
        }
        dao.updateById(entityDo);
        for (OrderBackAddItem item : req.getItems()) {
            OrderBackProductDo productDo = new OrderBackProductDo();
            productDo.setCount(item.getCount());
            productDo.setOrderId(entityDo.getId());
            productDo.setCreateBy(userId);
            productDo.setCreateTime(new Date());
            productDo.setProductId(item.getProductId());
            verfyProduct(item.getProductId(), req.getCompanyId());
            productDo.setDeleteFlag(SysConstant.DELETE_FLAG_FALSE);
            orderBackProductDao.insert(productDo);
        }
        operateRecordDao.operateAddRecord(SysConstant.OPERATE_CREATE_BACK, entityDo.getId(), userId, 8);
        //异步推送公众号
        executor.execute(() -> {
            wxUserService.orderBack(entityDo);
        });
        return req;
    }

    private void verfyProduct(Long productId, Long companyId) {
        ProductInfoDo productInfoDo = productInfoDao.selectById(productId);
        if (productInfoDo == null) {
            throw new BizException(SysConstant.Product_NotExist);
        }
        if (!productInfoDo.getCompanyId().equals(companyId)) {
            throw new BizException(SysConstant.Product_Company_NotMatch);
        }
    }

    //新增校验
    private void addCheck(Object req) {

    }

    //做新增之前要执行的业务定制处理
    private void handlerAddBefore(OrderBackDo entityDo, Long userId) {
        entityDo.setCreateBy(userId);
        entityDo.setCreateTime(new Date());
        entityDo.setDeleteFlag(SysConstant.DELETE_FLAG_FALSE);
    }

    @Override
    public Map processorStorage(OrderBackProcessorStorageReq req, Long userId) {
        OrderBackDo orderBackDo = dao.selectById(req.getId());
        if (orderBackDo == null || orderBackDo.getDeductFee() == 1) {
            throw new BizException(SysConstant.OrderBack_Repeat_Error);
        }
        orderBackDo.setFileId(req.getFileId());

        orderBackDo.setOperateFee(req.getOperateFee());
        orderBackDo.setShipFee(req.getShipFee());
        //退货费用的税费计算
        //税费=运输费*0.1+操作费*0.1+废弃费*0.1+运输费*0.04+运输费*0.04*0.1
        orderBackDo.setTaxFee(req.getOperateFee() * 0.1 + req.getShipFee() * 0.14);
        if (req.getShipFee() > 0) {
            orderBackDo.setHasFee(1);
        }
        if (orderBackDo.getDeductFee() == 0) {
//            dealWithFee(orderBackDo, userId);
        }
//        orderBackDo.setDeductFee(1);
        updateById(orderBackDo);
        Map map = new HashMap();
        return map;
    }

    @Override
    public void customerProcessing(OrderBackCustomerProcessingReq req, Long userId) {
        OrderBackDo orderBackDo = dao.selectById(req.getId());
        if (orderBackDo == null) {
            throw new BizException(SysConstant.Order_NotExist1);
        }
        if (orderBackDo.getShopId() == null) {
            throw new BizException(SysConstant.OrderBack_Deal_Error);
        }
        if (DicBusinessItemConstant.orderBackFinish > orderBackDo.getStatus() && req.getCompleted() != 1) {
            throw new BizException(SysConstant.OrderBack_HadComplete);
        }
        if (orderBackDo.getStatus() < DicBusinessItemConstant.orderBackInstructions) {
            handler2Comstomer(req, userId, orderBackDo);
            return;
        }
        if (StringUtils.isNotBlank(req.getTips())) {
            orderBackDo.setTips(orderBackDo.getTips() + "仓库处理回复：" + req.getTips());
        }
        if (DicBusinessItemConstant.orderBackFinish < orderBackDo.getStatus()) {
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackFinish);
            if (req.getOperate() == 1) {//上架
                handlerPutaway(req, userId, orderBackDo, req.getOperate());
            } else if (req.getOperate() == 2) {//不良品上架
                handlerPutaway(req, userId, orderBackDo, req.getOperate());
            } else if (req.getOperate() == 3) {//废弃
                handlerAbandon(req, userId, orderBackDo);
            } else if (req.getOperate() == 4) {
                orderBackDo.setBackResult(DicBusinessItemConstant.orderBackWorkOrder);
                handlerWorkOrder(req, userId, orderBackDo);
            }
        }
        LambdaQueryWrapper<OrderOutputDo> orderOutputDoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        orderOutputDoLambdaQueryWrapper.eq(OrderOutputDo::getOrderOutputNumber, orderBackDo.getOrderOutNumber());
        OrderOutputDo orderOutputDo = orderOutputDao.selectOne(orderOutputDoLambdaQueryWrapper);
        if (orderOutputDo != null) {
            //原订单状态改为已追回
            orderOutputDo.setStatus(DicBusinessItemConstant.outOrderBack);
            orderOutputDao.updateById(orderOutputDo);
        }
        if (StringUtils.isNotBlank(req.getTips()))
            orderBackDo.setTips(orderBackDo.getTips() == null ? req.getTips() : orderBackDo.getTips() + "仓库回复：" + req.getTips());
        updateById(orderBackDo);
        operateRecordDao.operateAddRecord(SysConstant.OPERATE_DEAL_BACK, orderBackDo.getId(), userId, 8);
//        operateRecord("处理", orderBackDo.getId(), userId);
//        dealWithFee(orderBackDo);
        if (orderBackDo.getDeductFee() == 0
                && req.getCompleted() == 1)
            dealWithFee(orderBackDo, userId);
    }

    /**
     * 帮助顾客指示处理结果
     *
     * @param req
     * @param userId
     * @param orderBackDo
     */
    private void handler2Comstomer(OrderBackCustomerProcessingReq req, Long userId, OrderBackDo orderBackDo) {
        orderBackDo.setUpdateBy(userId);
        orderBackDo.setUpdateTime(new Date());
        if (req.getOperate() == 1) {//上架
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackPutAway);
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackInstructions);
        } else if (req.getOperate() == 2) {//上架
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackPutAwayBroken);
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackInstructions);
        } else if (req.getOperate() == 3) {//废弃
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackAbandon);
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackInstructions);
        } else if (req.getOperate() == 4) {//定制工单
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackWorkOrder);
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackFinish);
        }
        dao.updateById(orderBackDo);
        LambdaQueryWrapper<OrderBackProductDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackProductDo::getOrderId, req.getId());
        List<OrderBackProductDo> orderBackProductDos = orderBackProductDao.selectList(wrapper);
        if (!CollectionUtils.isEmpty(orderBackProductDos)) {
            orderBackProductDos.forEach(orderBackProductDo -> {
                if (orderBackProductDo.getProductId() == null) {
                    throw new BizException(SysConstant.OrderBack_ProductId_IsNull);
                }
            });
        }
        operateRecordDao.operateAddRecord(SysConstant.OPERATE_ADMIN_INDICATION_ORDER, orderBackDo.getId(), userId, 8);

//        operateRecord("后台指示", orderBackDo.getId(), userId);
    }

    private void dealWithFee(OrderBackDo orderBackDo, Long userId) {
        String operate = null;
        DicBusinessItemDo itemDo = dicBusinessItemDao.selectById(orderBackDo.getBackResult());
        if (itemDo != null) operate = itemDo.getDicItemValue();
        if (operate == null) operate = "接收";
        operateRecordDao.operateAddRecord(SysConstant.OPERATE_DEDUCTION_FEE_BACK, orderBackDo.getId(), userId, 8);
//        operateRecord("扣费", orderBackDo.getId(), userId);
        orderBackDo.setDeductFee(1);
        orderBackDo.setStatus(DicBusinessItemConstant.orderBackFinish2);
        //重新算 税费 退货费用的税费计算
        //税费=运输费*0.1+操作费*0.1+废弃费*0.1+运输费*0.04+运输费*0.04*0.1
        double taxFee = orderBackDo.getShipFee() * 0.1 + orderBackDo.getDropFee() * 0.1 + orderBackDo.getOperateFee() * 0.1 + orderBackDo.getShipFee() * 0.04 + orderBackDo.getShipFee() * 0.04 * 0.1;
        orderBackDo.setTaxFee(taxFee);
        updateById(orderBackDo);
        //退货费用的税费计算  税费=运输费*0.1+操作费*0.1+废弃费*0.1+运输费*0.04+运输费*0.04*0.1
        costService.add(4, orderBackDo.getOrderOutNumber() + "退货费用", orderBackDo.getShipFee() + orderBackDo.getOperateFee() + orderBackDo.getDropFee() + orderBackDo.getTaxFee(), orderBackDo.getShopId(), orderBackDo.getCompanyId(), orderBackDo.getId());
    }

    private void handlerWorkOrder(OrderBackCustomerProcessingReq req, Long userId, OrderBackDo orderBackDo) {
//        orderBackDo.setUpdateBy(userId);
//        orderBackDo.setUpdateTime(new Date());
//
//        dao.updateById(orderBackDo);
    }

    private void handlerAbandon(OrderBackCustomerProcessingReq req, Long userId, OrderBackDo orderBackDo) {

        //计算所有退货商品价格
        double fee = 0;

        LambdaQueryWrapper<OrderBackProductDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackProductDo::getOrderId, req.getId());
        List<OrderBackProductDo> orderBackProductDos = orderBackProductDao.selectList(wrapper);
        if (!CollectionUtils.isEmpty(orderBackProductDos)) {
            for (OrderBackProductDo orderBackProductDo : orderBackProductDos) {
//                ProductInfoDo productInfoDo = productInfoDao.selectById(orderBackProductDo.getProductId());
//                if (productInfoDo != null) {
//                    fee += (productInfoDo.getHeight() * productInfoDo.getWidth() * productInfoDo.getLength()) * 0.014;
//                }
                if (orderBackProductDo.getCount() == null)
                    orderBackProductDo.setCount(1);
                fee += orderBackProductDo.getCount() * 500 * 1.1;
            }
        }
        if (orderBackDo.getCompanyId() == null) return;
        orderBackDo.setBackResult(DicBusinessItemConstant.orderBackAbandon);
        orderBackDo.setDropFee(fee);
        orderBackDo.setUpdateBy(userId);
        orderBackDo.setUpdateTime(new Date());
        dao.updateById(orderBackDo);

        //扣除废弃费用
//        costService.add(4, orderBackDo.getOrderOutNumber() + "废弃费用", fee, orderBackDo.getShopId(), orderBackDo.getCompanyId(), orderBackDo.getId());
    }

    private void handlerPutaway(OrderBackCustomerProcessingReq req, Long userId, OrderBackDo orderBackDo, Integer operate) {
        if (operate == 1) {
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackPutAway);
        } else {
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackPutAwayBroken);
        }
        orderBackDo.setUpdateBy(userId);
        orderBackDo.setUpdateTime(new Date());
        dao.updateById(orderBackDo);

        LambdaQueryWrapper<OrderBackProductDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackProductDo::getOrderId, req.getId());
        List<OrderBackProductDo> orderBackProductDos = orderBackProductDao.selectList(wrapper);
        if (!CollectionUtils.isEmpty(orderBackProductDos)) {
            orderBackProductDos.forEach(orderBackProductDo -> {
                LambdaQueryWrapper<StockRecordDo> stockRecordDoLambdaQueryWrapper = new LambdaQueryWrapper<>();
                stockRecordDoLambdaQueryWrapper.eq(StockRecordDo::getStorageId, orderBackDo.getStorageId()).eq(StockRecordDo::getShopId, orderBackDo.getShopId()).eq(StockRecordDo::getProductInfoId, orderBackProductDo.getProductId());

                StockRecordDo stockRecordDo = stockRecordDao.selectOne(stockRecordDoLambdaQueryWrapper);
                if (stockRecordDo != null) {
                    if (operate == 1) {
                        stockRecordDo.setCanSellCount(stockRecordDo.getCanSellCount() + orderBackProductDo.getCount());
                    } else {
                        stockRecordDo.setCanotSellCount(stockRecordDo.getCanotSellCount() + orderBackProductDo.getCount());
                    }
                    stockRecordDo.setUpdateBy(userId);
                    stockRecordDo.setUpdateTime(new Date());
                    stockRecordDao.updateById(stockRecordDo);
                } else {
                    stockRecordDo = new StockRecordDo();
                    if (operate == 1) {
                        stockRecordDo.setCanSellCount(stockRecordDo.getCanSellCount() + orderBackProductDo.getCount());
                    } else {
                        stockRecordDo.setCanotSellCount(stockRecordDo.getCanotSellCount() + orderBackProductDo.getCount());
                    }
                    stockRecordDo.setProductInfoId(orderBackProductDo.getProductId());
                    stockRecordDo.setDeleteFlag(SysConstant.DELETE_FLAG_FALSE);
                    stockRecordDo.setStorageId(orderBackDo.getStorageId());
                    stockRecordDo.setShopId(orderBackDo.getShopId());
                    stockRecordDo.setCompanyId(orderBackDo.getCompanyId());
                    stockRecordDao.insert(stockRecordDo);
                }
                //todo 加入新库位库存表
                ProductStockDo stockDo = new ProductStockDo();
                stockDo.setCompanyId(orderBackDo.getCompanyId());
                stockDo.setCreateBy(userId);
                stockDo.setCreateTime(new Date());
                stockDo.setProductId(orderBackProductDo.getProductId());
                stockDo.setStorageId(orderBackDo.getStorageId());
                if (operate == 1) {
                    stockDo.setGoodQuantity(orderBackProductDo.getCount());
                    stockDo.setReceiveGoodQuantity(stockDo.getGoodQuantity());
                    stockDo.setBadQuantity(0);
                } else {
                    stockDo.setGoodQuantity(0);
                    stockDo.setReceiveGoodQuantity(stockDo.getGoodQuantity());
                    stockDo.setBadQuantity(orderBackProductDo.getCount());
                }
                stockDo.setReceiveQuantity(stockDo.getGoodQuantity() + stockDo.getBadQuantity());
                stockDo.setOrderId(orderBackDo.getId());
                stockDo.setOrderType("OB");//入库单
//            stockDo.setShopId(orderInputDo.getShopId());
                if (stockDo.getReceiveQuantity() == 0) {
                    return;
                }
                //单位成本 * 单位体积
                productStockDao.insert(stockDo);

//                        if (rackMap.get(productId) == null || rackMap.get(productId).get(0).getList().size() == 0) {
                //添加到库位表
                ProductStockRackDo rackDo = new ProductStockRackDo();
                rackDo.setGoodQuantity(stockDo.getGoodQuantity());
                rackDo.setBadQuantity(stockDo.getBadQuantity());
                rackDo.setStockId(stockDo.getId());
                rackDo.setCreateTime(new Date());
                productStockRackDao.insert(rackDo);

                productStockFlowingService.insertFlowing(StaticDict.Product_Flowing_Type.Back.getValue(), orderBackDo.getOrderOutNumber(), orderBackDo.getShopId(), orderBackProductDo.getProductId(), orderBackDo.getStorageId(),
                        rackDo.getGoodQuantity(), rackDo.getBadQuantity(), 0, null, orderBackDo.getCompanyId(), userId, "退货单:"+orderBackDo.getOrderOutNumber()+" 入库");
//                        }
//                else {
//                    List<InputOrderRackReq> rackReqList = rackMap.get(productId).get(0).getList();
//                    if (rackReqList.stream().mapToInt(InputOrderRackReq::getAvailNum).sum() != rackMap.get(productId).get(0).getReceiveCount()) {
//                        throw new BizException("可售数量不等于 分配库位数量之和");
//                    }
//                    if (rackReqList.stream().mapToInt(InputOrderRackReq::getDamageNum).sum() != rackMap.get(productId).get(0).getBrokenCount()) {
//                        throw new BizException("破损数量不等于 分配库位数量之和");
//                    }
//                    for (InputOrderRackReq rackReq : rackReqList) {
//                        ProductStockRackDo rackDo = new ProductStockRackDo();
//                        rackDo.setGoodQuantity(rackReq.getAvailNum());
//                        rackDo.setBadQuantity(rackReq.getDamageNum());
//                        rackDo.setStockId(stockDo.getId());
//                        rackDo.setRackId(rackReq.getLocationId());
//                        rackDo.setCreateTime(new Date());
//                        productStockRackDao.insert(rackDo);
//
//                        //添加库存流水
//                        ProductStockFlowingDo flowingDo = new ProductStockFlowingDo();
//                        flowingDo.setType("input");
//                        flowingDo.setNoteNo(orderBackDo.getOrderOutNumber());
//                        flowingDo.setProductId(productId);
//                        flowingDo.setStorageId(orderBackDo.getStorageId());
//                        flowingDo.setGoodQuantity(rackReq.getAvailNum());
//                        flowingDo.setBadQuantity(rackReq.getDamageNum());
//                        flowingDo.setCreateTime(new Date());
//                        flowingDo.setCreateBy(userId);
//                        flowingDo.setCompanyId(orderBackDo.getCompanyId());
//                        flowingDo.setShopId(orderBackDo.getShopId());
//                        flowingDo.setRackId(rackReq.getLocationId());
//                        productStockFlowingDao.insert(flowingDo);
//                    }
//                    }
                //库存日志
                stockLogService.saveAutoSendOutLog(operate == 1 ? 0 : 1, orderBackProductDo.getProductId(), orderBackDo.getShopId(), orderBackDo.getStorageId(), orderBackProductDo.getCount(), stockRecordDo.getCanSellCount(), orderBackDo.getCompanyId(), userId, StringUtils.isNotBlank(orderBackDo.getOrderOutNumber()) ? orderBackDo.getOrderOutNumber() : "退货:" + orderBackDo.getId());
            });
        }

    }


    @Override
    public SingleResult updateInit(Long id, Long userId, Long companyId) {
        Map result = (Map) addInit(userId, companyId).getData();

        result.put("detail", detail(id));

        return SingleResult.success(result);
    }

    @Override
    public OrderBackUpdateReq update(OrderBackUpdateReq req, Long userId) {
        OrderBackDo entityDo = dao.selectById(req.getId());
        BeanUtils.copyProperties(req, entityDo);
        handlerUpdateBefore(entityDo, userId);
        dao.updateById(entityDo);


        LambdaQueryWrapper<OrderBackProductDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackProductDo::getOrderId, req.getId());
        orderBackProductDao.delete(wrapper);

        req.getItems().forEach(orderBackAddItem -> {
            OrderBackProductDo productDo = new OrderBackProductDo();
            productDo.setDeleteFlag(SysConstant.DELETE_FLAG_FALSE);
            productDo.setProductId(orderBackAddItem.getProductId());
            productDo.setCreateTime(new Date());
            productDo.setCreateBy(userId);
            productDo.setOrderId(req.getId());
            productDo.setCount(orderBackAddItem.getCount());
            orderBackProductDao.insert(productDo);
        });
        operateRecordDao.operateAddRecord(SysConstant.OPERATE_UPDATE_BACK, entityDo.getId(), userId, 8);

//        operateRecord("修改", entityDo.getId(), userId);
        return req;
    }

    //编辑校验
    private void updateCheck(Object req) {

    }

    //做修改之前要执行的业务定制处理
    private void handlerUpdateBefore(OrderBackDo entityDo, Long userId) {
        entityDo.setUpdateBy(userId);
        entityDo.setUpdateTime(new Date());
    }


    @Override
    public int delete(Long id, Long userId) {
        OrderBackDo entityDo = dao.selectById(id);
        handlerDeleteBefore(entityDo, userId);
        dao.updateById(entityDo);

        LambdaQueryWrapper<OrderBackProductDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackProductDo::getOrderId, id);
        orderBackProductDao.delete(wrapper);

        fileService.deleteFile(entityDo.getFileId());
        return dao.deleteById(id);
    }

    //做删除之前要执行的业务定制处理
    private void handlerDeleteBefore(OrderBackDo entityDo, Long userId) {
        entityDo.setDeleteBy(userId);
        entityDo.setDeleteTime(new Date());
    }

    @Override
    public OrderBackDetailRes detail(Long id) {
        OrderBackDo entityDo = dao.selectById(id);
        OrderBackDetailRes res = new OrderBackDetailRes();
        BeanUtils.copyProperties(entityDo, res);
        res.setFileId(entityDo.getFileId());
        res.setFileUrl(fileService.getFilePath(entityDo.getFileId()));
        if (entityDo.getProductFileId() != null) {
            try {
                List<String> urlData = new ArrayList<>();
                if (entityDo.getProductFileId().contains(",")) {
                    String[] split = entityDo.getProductFileId().split(",");
                    for (int i = 0; i < split.length; i++) {
                        String s = split[i];
                        urlData.add(fileService.getFilePath(Long.parseLong(s)));
                    }
                } else {
                    urlData.add(fileService.getFilePath(Long.parseLong(entityDo.getProductFileId())));
                }
                res.setProductFileUrl(urlData);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        if (entityDo.getDoubleCheckFileId() != null && StringUtils.isNotEmpty(entityDo.getDoubleCheckFileId())) {
            try {
                List<String> urlData = new ArrayList<>();
                if (entityDo.getDoubleCheckFileId().contains(",")) {
                    String[] split = entityDo.getDoubleCheckFileId().split(",");
                    for (int i = 0; i < split.length; i++) {
                        String s = split[i];
                        urlData.add(fileService.getFilePath(Long.parseLong(s)));
                    }
                } else {
                    urlData.add(fileService.getFilePath(Long.parseLong(entityDo.getDoubleCheckFileId())));
                }
                res.setDoubleCheckFileUrl(urlData);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        ShopDo shopDo = shopService.getBaseMapper().selectById(entityDo.getShopId());
        if (shopDo != null) {
            res.setShopName(shopDo.getShopName());
        }
        StorageDo storageDo = storageService.getBaseMapper().selectById(entityDo.getStorageId());
        if (storageDo != null) {
            res.setStorageName(storageDo.getStorageName());
        }
        String status = dicBusinessItemService.getDicItemValue(entityDo.getStatus());
        if (StringUtils.isNotBlank(status)) {
            res.setStatus(status);
            if (entityDo.getDoubleCheck() == 1 && entityDo.getBackResult() == null && (entityDo.getStatus() == DicBusinessItemConstant.orderBackInStatus
                    || entityDo.getStatus() == DicBusinessItemConstant.orderBackInstructions)) {
                res.setStatus(status + StringsUtil.createI18Message("(二次确认)"));
            }
        }
        res.setBackResult(dicBusinessItemService.getDicItemValue(entityDo.getBackResult()));

        if (entityDo.getArrivalTime() != null) {
            res.setArriveDate(TimeUtils.formatDate(entityDo.getArrivalTime(), "MM月dd日"));
        }
        if (entityDo.getLastDate() != null) {
            res.setLastDate(TimeUtils.formatDate(entityDo.getLastDate(), "MM月dd日"));
        }
        if (entityDo.getDealDate() != null) {
            res.setDealDate(TimeUtils.formatDate(entityDo.getDealDate(), "MM月dd日"));
        }
        res.setOpenBox(entityDo.getOpenBox() == 0 ? "未开箱" : "已开箱");
        res.setCanSale(entityDo.getCanSale() == 0 ? "可贩卖" : (entityDo.getCanSale() == 1 ? "不可贩卖" : "待确认"));
        res.setHasFee(entityDo.getHasFee() == 1 ? String.format("有(%d)", entityDo.getShipFee().intValue()) : (entityDo.getHasFee() == 0 ? "无" : "-"));
        res.setDeductFee(entityDo.getDeductFee() == 1 ? "已收款" : "未收款");
        List<OrderBackDetailItem> items = new ArrayList<>();
        LambdaQueryWrapper<OrderBackProductDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackProductDo::getOrderId, id);
        double l = 0, w = 0, h = 0, we = 0;
        double[] sizeTemp = new double[4];
        List<OrderBackProductDo> orderBackProductDos = orderBackProductDao.selectList(wrapper);
        for (OrderBackProductDo orderBackProductDo : orderBackProductDos) {
            OrderBackDetailItem item = new OrderBackDetailItem();
            item.setCount(orderBackProductDo.getCount());
            ProductInfoDo productInfoDo = productInfoDao.selectById(orderBackProductDo.getProductId());
            if (productInfoDo != null) {
                item.setProductId(productInfoDo.getId());
                item.setProductName(productInfoDo.getProductName());
                item.setSku(productInfoDo.getCommoditySku());
                sizeTemp = mShipPriceService.countSameSkuSizeNew(sizeTemp, productInfoDo.getId(), orderBackProductDo.getCount());
            } else {
                sizeTemp = mShipPriceService.countSameSkuSizeNew(sizeTemp, orderBackProductDo.getLength() == null ? 0 : orderBackProductDo.getLength(), orderBackProductDo.getWidth() == null ? 0 : orderBackProductDo.getWidth(), orderBackProductDo.getHeight() == null ? 0 : orderBackProductDo.getHeight(), orderBackProductDo.getWeight() == null ? 0 : orderBackProductDo.getWeight(), orderBackProductDo.getCount());
            }
            items.add(item);
        }
        res.setPackageLength(sizeTemp[0]);
        res.setPackageWidth(sizeTemp[1]);
        res.setPackageHeight(sizeTemp[2]);
        res.setPackageWeight(sizeTemp[3]);
        res.setItems(items);
        res.setOperateResList(operateRecordDao.getOperateList(entityDo.getId(), 8));
        return res;
    }

    //查询明细之后要执行的业务定制处理
    private Object handlerDetailAfter(Object res) {
        return res;
    }

    @Override
    public SingleResult pageInit(Long companyId, Long currentUserId) {
        Map map = new HashMap();
        map.put("shopList", companyService.getInitList(null));
        map.put("statusList", dicBusinessItemService.getDicItemList(DicBusinessConstant.orderBackStatus));
        map.put("resultList", dicBusinessItemService.getDicItemList(DicBusinessConstant.orderBackResult));
        map.put("storageList", storageService.getStorageList());
        return SingleResult.success(map);
    }

    @Override
    public List<OrderBackPageRes> getList(Map<String, String> map) {
        QueryWrapper<OrderBackDo> wrapper = queryBuild(map);
        List<OrderBackDo> list = this.list(wrapper);
        List<OrderBackPageRes> result = handlerListAfter(list);
        return result;
    }

    @Override
    public PageResult getListPage(Map<String, String> map) {
        QueryWrapper<OrderBackDo> wrapper = queryBuild(map);
        IPage<OrderBackDo> page = pageInit(map);
        page = this.page(page, wrapper);
        List<OrderBackPageRes> resList = handlerListAfter(page.getRecords());
        PageResult result = new PageResult(resList, (int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal(), (int) page.getPages());
        return result;
    }

    @Override
    public SingleResult productType() {
        List<Map> productTypeList = new ArrayList<>();
        LambdaQueryWrapper<DicBusinessItemDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DicBusinessItemDo::getDicBusinessId, DicBusinessConstant.productType);
        List<DicBusinessItemDo> businessItemDoList = dicBusinessItemDao.selectList(wrapper);
        if (!CollectionUtils.isEmpty(businessItemDoList)) {
            for (DicBusinessItemDo businessItemDo : businessItemDoList) {
                Map map = new HashMap();
                map.put("id", businessItemDo.getId());
                map.put("value", businessItemDo.getDicItemValue());
                productTypeList.add(map);
            }
        }
        return SingleResult.success(productTypeList);
    }

    //查询分页列表之后对列表数据的处理
    private List<OrderBackPageRes> handlerListAfter(List<OrderBackDo> list) {
        List<OrderBackPageRes> result = new ArrayList<>();
        if (!CollectionUtils.isEmpty(list)) {
            list.forEach(orderBackDo -> {
                OrderBackPageRes res = new OrderBackPageRes();
                BeanUtils.copyProperties(orderBackDo, res);

                ShopDo shopDo = shopService.getBaseMapper().selectById(orderBackDo.getShopId());
                if (shopDo != null) {
                    res.setShopName(shopDo.getShopName());
                } else {
                    res.setShopName(StringsUtil.createI18Message("待认领"));
                }
                CompanyDo companyDo = companyService.getBaseMapper().selectById(orderBackDo.getCompanyId());
                if (companyDo != null) {
                    res.setCompanyCode(companyDo.getCompanyCode());
                } else {
                    res.setCompanyCode(StringsUtil.createI18Message("待认领"));
                }
                res.setHasFee(orderBackDo.getHasFee() == 1 ? String.format("有(%d)", orderBackDo.getShipFee().intValue()) : "无");
                res.setDeductFee(orderBackDo.getDeductFee() == 1 ? "已收款" : (orderBackDo.getHasFee() == 0 ? "无需收款" : "未收款"));
                StorageDo storageDo = storageService.getBaseMapper().selectById(orderBackDo.getStorageId());
                if (storageDo != null) {
                    res.setStorageName(storageDo.getStorageName());
                }
                String status = dicBusinessItemService.getDicItemValue(orderBackDo.getStatus());
                if (StringUtils.isNotBlank(status)) {
                    res.setStatus(status);
                    if (orderBackDo.getDoubleCheck() == 1 && (orderBackDo.getBackResult() == null || orderBackDo.getBackResult() == 0L) && (orderBackDo.getStatus() == DicBusinessItemConstant.orderBackInStatus
                            || orderBackDo.getStatus() == DicBusinessItemConstant.orderBackInstructions)) {
                        res.setStatus(status + StringsUtil.createI18Message("(二次确认)"));
                    }
                }
                res.setBackResult(dicBusinessItemService.getDicItemValue(orderBackDo.getBackResult()));

                res.setBackResultId(orderBackDo.getBackResult());
                if (orderBackDo.getArrivalTime() != null) {
                    res.setArriveDate(TimeUtils.formatDate(orderBackDo.getArrivalTime(), "MM月dd日"));
                } else {
                    res.setArriveDate(TimeUtils.formatDate(orderBackDo.getCreateTime(), "MM月dd日"));
                }
                if (orderBackDo.getLastDate() != null) {
                    res.setLastDate(TimeUtils.formatDate(orderBackDo.getLastDate(), "MM月dd日"));
                }
                if (orderBackDo.getDealDate() != null) {
                    res.setDealDate(TimeUtils.formatDate(orderBackDo.getDealDate(), "MM月dd日"));
                }
                res.setOpenBox(orderBackDo.getOpenBox() == 0 ? "未开箱" : "已开箱");
                res.setCanSale(orderBackDo.getCanSale() == 0 ? "可贩卖" : (orderBackDo.getCanSale() == 1 ? "不可贩卖" : "待确认"));
                res.setHasFee(orderBackDo.getHasFee() == 1 ? String.format("有(%d)", orderBackDo.getShipFee().intValue()) : "无");
                res.setDeductFee(orderBackDo.getDeductFee() == 1 ? "已收款" : "未收款");
                result.add(res);
            });
        }
        return result;
    }

    private IPage<OrderBackDo> pageInit(Map<String, String> map) {
        IPage<OrderBackDo> page = new Page();
        page.setSize(StringUtils.isNotBlank(map.get("pageSize")) ? Long.parseLong(map.get("pageSize")) : 10);
        page.setCurrent(StringUtils.isNotBlank(map.get("current")) ? Long.parseLong(map.get("current")) : 1);
        return page;
    }

    private QueryWrapper<OrderBackDo> queryBuild(Map<String, String> map) {
        QueryWrapper<OrderBackDo> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(map.get("keyword"))) {
            wrapper.like("order_out_number", map.get("keyword")).or();
            wrapper.like("contact_name", map.get("keyword")).or();
            wrapper.like("track_number", map.get("keyword"));
        }
        if (StringUtils.isNotBlank(map.get("status"))) {
            wrapper.eq("status", map.get("status"));
        }
        if (StringUtils.isNotBlank(map.get("result"))) {
            wrapper.eq("back_result", map.get("result"));
        }
        if (StringUtils.isNotBlank(map.get("companyId"))) {
            wrapper.eq("company_id", map.get("companyId"));
        }
        if (StringUtils.isNotBlank(map.get("storageId"))) {
            wrapper.eq("storage_id", map.get("storageId"));
        }
        return wrapper.orderByDesc("arrival_time");
    }

    @Override
    public void autoDropOverTime() {
        LambdaUpdateWrapper<OrderBackDo> orderBackDoWrapper = new LambdaUpdateWrapper<>();

        orderBackDoWrapper.eq(OrderBackDo::getStatus, DicBusinessItemConstant.orderBackInStatus);
        orderBackDoWrapper.eq(OrderBackDo::getDoubleCheck, 0);
        orderBackDoWrapper.isNotNull(OrderBackDo::getCompanyId);
        orderBackDoWrapper.lt(OrderBackDo::getCreateTime, TimeUtils.getCurrentDateFormat(-7));
        List<OrderBackDo> orderBackDoList = dao.selectList(orderBackDoWrapper);
        if (orderBackDoList == null || orderBackDoList.size() < 1) {
            return;
        }
        for (OrderBackDo orderBackDo : orderBackDoList) {
            //     orderBackDoWrapper.set(OrderBackDo::getBackResult, DicBusinessItemConstant.orderBackAbandon);
            //        orderBackDoWrapper.set(OrderBackDo::getUpdateTime, new Date());
            //        orderBackDoWrapper.set(OrderBackDo::getStatus, DicBusinessItemConstant.orderBackFinish);
            //        orderBackDoWrapper.set(OrderBackDo::getTips, "超时自动废弃");
            OrderBackCustomerProcessingReq req = new OrderBackCustomerProcessingReq();
            req.setId(orderBackDo.getId());
            req.setOperate(3);
            orderBackDo.setAutoDrop(0);
            req.setTips("超时自动废弃");
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackFinish);
            if (orderBackDo.getCompanyId() == null) return;
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackAbandon);
            orderBackDo.setUpdateBy(1L);
            operateRecordDao.operateAddRecord(SysConstant.OPERATE_INDICATION_AUTO_DROP, orderBackDo.getId(), 1L, 8);
            orderBackDo.setUpdateTime(new Date());
            dao.updateById(orderBackDo);
        }
    }

    @Override
    public void autoDropOverTime2() {
        LambdaUpdateWrapper<OrderBackDo> orderBackDoWrapper = new LambdaUpdateWrapper<>();

        orderBackDoWrapper.eq(OrderBackDo::getStatus, DicBusinessItemConstant.orderBackInStatus);
        orderBackDoWrapper.eq(OrderBackDo::getDoubleCheck, 1);
        orderBackDoWrapper.isNotNull(OrderBackDo::getCompanyId);
        orderBackDoWrapper.lt(OrderBackDo::getUpdateTime, TimeUtils.getCurrentDateFormat(-7));
        List<OrderBackDo> orderBackDoList = dao.selectList(orderBackDoWrapper);
        if (orderBackDoList == null || orderBackDoList.size() < 1) {
            return;
        }
        dealWithAutoDropOrder(orderBackDoList);

    }

    public void dealWithAutoDropOrder(List<OrderBackDo> orderBackDoList) {
        for (OrderBackDo orderBackDo : orderBackDoList) {
            //     orderBackDoWrapper.set(OrderBackDo::getBackResult, DicBusinessItemConstant.orderBackAbandon);
            //        orderBackDoWrapper.set(OrderBackDo::getUpdateTime, new Date());
            //        orderBackDoWrapper.set(OrderBackDo::getStatus, DicBusinessItemConstant.orderBackFinish);
            //        orderBackDoWrapper.set(OrderBackDo::getTips, "超时自动废弃");
            OrderBackCustomerProcessingReq req = new OrderBackCustomerProcessingReq();
            req.setId(orderBackDo.getId());
            req.setOperate(3);
            orderBackDo.setAutoDrop(0);
            req.setTips("超时自动废弃");
            orderBackDo.setStatus(DicBusinessItemConstant.orderBackFinish);
            if (orderBackDo.getCompanyId() == null) return;
            orderBackDo.setBackResult(DicBusinessItemConstant.orderBackAbandon);
            orderBackDo.setUpdateBy(1L);
            orderBackDo.setUpdateTime(new Date());
            dao.updateById(orderBackDo);
        }
    }


    @Override
    public List<Map<String, String>> getFileList(Long id) {
        OrderBackDo et = dao.selectById(id);
        if (et == null) {
            throw new BizException(SysConstant.Error_Data_NotExist);
        }
        List<Map<String, String>> resultList = new ArrayList<>();

        if (filePath.startsWith("http")) {
            List<OSSObjectSummary> fileList = AliOss.getFileList();
            for (OSSObjectSummary ossFile : fileList) {
                //判断一下创建时间 是不是 前后5分钟
                if (Math.abs(et.getCreateTime().getTime() - ossFile.getLastModified().getTime()) > 1000 * 60 * 5) {
                    continue;
                }
                //获取fileId
                //key: cloudkint-file/temporaryFile/41184.jpeg
                Map<String, String> map = this.getFileMap(ossFile.getKey());
                if (map == null) {
                    continue;
                }
                if (ossFile.getLastModified() != null) {
                    map.put("lastModified", DateUtils.dateFormatToString(ossFile.getLastModified(), "yyyy-MM-dd HH:mm:ss"));
                }
                resultList.add(map);
            }
        } else {
            //本地
            File fileDir = new File(filePathTemp);
            File[] files = fileDir.listFiles();
            if (files != null) {
                for (File file : files) {
                    Map<String, String> map = this.getFileMap(file.getName());
                    if (map == null) {
                        continue;
                    }
                    resultList.add(map);
                }
            }
        }
        return resultList;
    }

    public Map<String, String> getFileMap(String key) {
        //判断后缀
        String suffix = key.substring(key.lastIndexOf(".") + 1);
        if (StringUtils.isBlank(suffix) || !GlobalConstants.IMG_SUFFIX.contains(suffix)) {
            return null;
        }
        String fileIdStr = key.substring(key.lastIndexOf("/") + 1, key.lastIndexOf("."));
        if (!fileIdStr.matches("[0-9]+")) {
            return null;
        }
        Long fileId = Long.parseLong(fileIdStr);
        String url = fileService.getFilePathTemp(fileId);
        if (StringUtils.isBlank(url)) {
            return null;
        }
        Map<String, String> map = new HashMap<>();
        map.put("id", fileIdStr);
        map.put("url", url);
        return map;
    }

    @Override
    public void selectPicture(OrderBackPicReq req) {
        OrderBackDo et = dao.selectById(req.getId());
        if (et == null) {
            throw new BizException(SysConstant.Error_Data_NotExist);
        }

        if (req.getFileId() == null && (req.getProductFileId() == null || req.getProductFileId().length == 0)) {
            throw new BizException(SysConstant.Pls_Choose_File);
        }

        if (req.getFileId() != null) {
            fileService.uploadFile(req.getFileId());
            et.setFileId(req.getFileId());
        }

        if (req.getProductFileId() != null) {
            for (int i = 0; i < req.getProductFileId().length; i++) {
                fileService.uploadFile(req.getProductFileId()[i]);
            }
            et.setProductFileId(StringUtils.join(req.getProductFileId(), ","));
        }
        dao.updateById(et);
    }


    @Override
    public void autoCompletedOrder() {

        LambdaQueryWrapper<OrderBackDo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderBackDo::getCompanyId, 201)
                .gt(OrderBackDo::getCreateTime, "2023-04-01")
                .lt(OrderBackDo::getCreateTime, "2023-05-01")
                .eq(OrderBackDo::getStatus, 49)
                .in(OrderBackDo::getOrderOutNumber, "BO2023042711465", "BO2023050311600", "BO2023042711363", "BO2023050911782", "BO2023040310816", "BO2023041911268", "BO2023042411401", "BO2023051411903", "BO2023042011187", "BO2023041911210", "BO2023041911242", "BO2023042211327", "BO2023042411387", "BO2023042411364", "BO2023042211360", "BO2023050811613", "BO2023050611777", "BO2023041411189", "BO2023042411441", "BO2023043011554", "BO2023050911825", "BO2023050911857", "BO2023051311907", "BO2023040610800", "BO2023041311155", "BO2023042711493", "BO2023043011546", "BO2023050911761", "BO2023051311964", "BO2023040210784", "BO2023041211070", "BO2023041210998", "BO2023042211328", "BO2023050311634", "BO2023051011887", "BO2023040610901", "BO2023050311632", "BO2023050311633", "BO2023051311911", "BO2023051311928", "BO2023040610754", "BO2023042711507", "BO2023051311872", "BO2023041911213", "BO2023042011270", "BO2023042211346", "BO2023051011718", "BO2023050511721", "BO2023050911844", "BO2023051311920", "BO2023042711505", "BO2023043011566", "BO2023051411912", "BO2023040610936", "BO2023041211104", "04102-55", "BO2023041511219", "BO2023050911549", "BO2023051311921", "BO2023041211069", "BO2023042711498", "BO2023041311160", "BO2023042411413", "BO2023051011867", "BO2023051311917", "BO2023041411157", "BO2023042711468", "BO2023051011849", "BO2023040610935", "BO2023042411361", "BO2023040210801", "BO2023041211119", "04102-15", "BO2023041911253", "BO2023042411388", "BO2023042711476", "BO2023050311631", "BO2023050311557", "BO2023041911254", "BO2023042411423", "BO2023040510795", "BO2023041211121", "04102-17", "BO2023041311180", "BO2023040610851", "BO2023042411437", "BO2023051011617", "BO2023042411397", "BO2023042711473", "BO2023042711495", "BO2023042711509", "BO2023043011520", "BO2023050911858", "BO2023051311896", "BO2023040310787", "BO2023040210806", "BO2023041211062", "BO2023050611778", "BO2023040810986", "BO2023041211076", "BO2023042411414", "BO2023042411444", "BO2023042711466", "BO2023042711467", "BO2023051011783", "BO2023051011883", "BO2023040510949", "0495-15", "BO2023041211061", "BO2023042711479", "BO2023051011713", "BO2023050911790", "BO2023051311865", "BO2023040210785", "BO2023040210797", "BO2023050511712", "BO2023051311942", "BO2023041411111", "BO2023041411170", "BO2023042211336", "BO2023050911764", "BO2023041210985", "BO2023041511214", "BO2023042411425", "BO2023042711506", "BO2023043011552", "BO2023051311906", "BO2023040610966", "BO2023041211039", "BO2023050911768", "BO2023042411409", "BO2023043011561", "BO2023050811614", "BO2023051411938", "BO2023041411161", "BO2023041411162", "BO2023041911247", "BO2023042411403", "BO2023043011529", "BO2023051311913", "BO2023040310841", "BO2023042211324", "BO2023042211344", "BO2023042411400", "BO2023051011878", "BO2023040310794", "BO2023041011046", "BO2023041211144", "04102-48", "BO2023041911165", "BO2023041311182", "BO2023041511212", "BO2023042711471", "BO2023050911789", "BO2023041911267", "BO2023051311893", "BO2023051311923", "BO2023041211060", "BO2023040810840", "BO2023040710984", "BO2023040811008", "BO2023042011322", "BO2023042711355", "BO2023042411456", "BO2023050911717", "BO2023050911792", "BO2023051011877", "BO2023051011886", "BO2023042711438", "BO2023050311638", "BO2023050311630", "BO2023051311901", "BO2023042211358", "BO2023042411410", "BO2023051011851", "BO2023041311166", "BO2023042411454", "BO2023040210798", "BO2023040610957", "BO2023041211147", "04102-51", "BO2023051411914", "BO2023040310836", "BO2023041411037", "BO2023042211342", "BO2023042411347", "BO2023050911766", "BO2023042711412", "BO2023041111078", "04101-1", "BO2023041911256", "BO2023042411402", "BO2023042711485", "BO2023042711501", "BO2023041311109", "BO2023041911238", "BO2023042411398", "BO2023043011563", "BO2023050911796", "BO2023041911243", "BO2023043011547", "BO2023050311637", "BO2023050911760", "BO2023051011868", "BO2023051311915", "BO2023040310815", "BO2023040410907", "BO2023041911272", "BO2023042411405", "BO2023040710978", "BO2023040710979", "BO2023050911765", "BO2023051311830", "BO2023040310837", "0493-28", "BO2023041911240", "BO2023042411415", "BO2023050511720", "BO2023051011828", "BO2023041911264", "BO2023050911767", "BO2023051011864", "BO2023051311905", "BO2023051311909", "BO2023040610974", "BO2023041211006", "BO2023042211307", "BO2023042411389", "BO2023050911758", "BO2023050911771", "BO2023040410910", "BO2023041211065", "BO2023041211067", "BO2023041311163", "BO2023042411422", "BO2023042411436", "BO2023042711480", "BO2023051311845", "BO2023041911252", "BO2023042411386", "BO2023050911763", "BO2023051311863", "BO2023040310814", "BO2023041911230", "BO2023050911794", "BO2023040210802", "BO2023040410859", "BO2023040811007", "BO2023041511211", "BO2023042411356", "BO2023051011842", "BO2023051311889", "BO2023051311922", "BO2023042711492", "BO2023051311963", "BO2023041311164", "BO2023041911188", "BO2023042411408", "BO2023051411991", "BO2023040210790", "BO2023041511185", "BO2023042211321", "BO2023042411351", "BO2023050911714", "BO2023050911786", "BO2023042211345", "BO2023042711497", "BO2023051311854", "BO2023040310796", "BO2023040610850", "BO2023042411426", "BO2023043011499", "BO2023042711542", "BO2023040310834", "BO2023041511197", "BO2023050911784", "BO2023040811003", "BO2023042711427", "BO2023042711496", "BO2023050611779", "BO2023051411925", "BO2023051311939", "BO2023040210748", "BO2023040410915", "BO2023041911269", "BO2023042211350", "BO2023041411192", "BO2023041911250", "BO2023040510937", "BO2023043011560", "BO2023041211110", "BO2023043011564", "BO2023050911715", "BO2023042411418", "BO2023050311558", "BO2023042711487", "BO2023050311615", "BO2023040310752", "BO2023040510934", "BO2023041911239", "BO2023041911262", "BO2023042711352", "BO2023042711472", "BO2023042711503", "BO2023042711508", "BO2023051011772", "BO2023051011826", "BO2023041411191", "BO2023041911251", "BO2023042011297", "BO2023051011853", "BO2023051411918", "BO2023050911759", "BO2023041911217", "BO2023050911787", "BO2023050911791", "BO2023040510933", "BO2023042211337", "BO2023042711463", "BO2023042711528", "BO2023051311869", "BO2023051311960", "BO2023042211338", "BO2023042411439", "BO2023042711494", "BO2023051411935", "BO2023040210808", "BO2023041510939", "BO2023041011010", "BO2023041211105", "04102-56", "BO2023051311888", "BO2023040510925", "BO2023041411168", "BO2023041211064", "BO2023042011326", "BO2023050911861", "BO2023051011882", "BO2023042411455", "BO2023042711483", "BO2023050911770", "BO2023041411190", "BO2023042211375", "BO2023042411420", "BO2023050311618", "BO2023041411193", "BO2023041911273", "BO2023042411399", "BO2023051311897", "BO2023051411894", "BO2023042411424", "BO2023043011553", "BO2023050911762", "BO2023051311898", "BO2023041411167", "BO2023050511711", "BO2023040310728", "BO2023041211126", "04102-29", "BO2023041911248", "BO2023041911263", "BO2023042711475", "BO2023050911795", "BO2023051011862", "BO2023041210980", "BO2023040911009", "BO2023041911186", "BO2023042411394", "BO2023043011559", "BO2023050311616", "BO2023050311642", "BO2023041511229", "BO2023042411443", "BO2023050911827", "BO2023041311159", "BO2023042211343", "BO2023042411390", "BO2023040410849", "BO2023042411393", "BO2023051311895", "BO2023051311931", "BO2023042211354", "BO2023040410896", "BO2023051011880", "BO2023051311904", "BO2023051311916", "BO2023043011562", "BO2023050911838", "BO2023041311158", "BO2023041411184", "BO2023041911249", "BO2023041911258", "BO2023042711464", "BO2023043011482", "BO2023042211274", "BO2023042211353", "BO2023042711395", "BO2023042411440", "BO2023051311962", "BO2023040610962", "0496-12", "BO2023041911260", "BO2023042211329", "BO2023051311919", "BO2023040410906", "BO2023041211011", "BO2023042211276", "BO2023042011325", "BO2023042711462", "BO2023042711481", "BO2023041211148", "04102-52", "BO2023042411396", "BO2023050911551", "BO2023041911257", "BO2023041911265", "BO2023042411416", "BO2023043011565", "BO2023040310751", "BO2023040210793", "BO2023041911209", "BO2023041911215", "BO2023041911275", "BO2023042411406", "BO2023051311961", "BO2023040210805", "BO2023042211349", "BO2023042411407", "BO2023041210983", "BO2023042711500", "BO2023043011550", "BO2023040210645", "BO2023041911261", "BO2023042411392", "BO2023042411419", "BO2023050811824", "BO2023040310799", "BO2023041411169", "BO2023050811502", "BO2023050911639", "BO2023042411404", "BO2023051311900", "BO2023051311940", "BO2023040610848", "BO2023040810997", "BO2023041911271", "BO2023040210744", "BO2023041211074", "BO2023042211359", "BO2023050911470", "BO2023050911775", "BO2023051311937", "BO2023042011259", "BO2023042411417", "BO2023050911855", "BO2023051311924", "BO2023040210781", "BO2023040310817", "BO2023040610919", "BO2023050311641", "BO2023040210782", "BO2023040610887", "BO2023042711510", "BO2023050511719", "BO2023051311866", "BO2023051411933", "BO2023042211348", "BO2023040210786", "BO2023043011598", "BO2023051411927", "BO2023041910982", "BO2023051011850", "BO2023051411899", "BO2023040610791", "BO2023041211071", "BO2023042711411", "BO2023050911785", "BO2023041211123", "BO2023041211136", "BO2023041911266", "BO2023042211323", "BO2023051311870", "BO2023051311926");
        List<OrderBackDo> orderBackDoList = dao.selectList(wrapper);
        for (OrderBackDo orderBackDo : orderBackDoList) {
            dealWithFee(orderBackDo, 1L);
        }
    }
}
